<?php

namespace app\api\controller\haibao;

use app\admin\model\HaibaoVideo;
use app\api\controller\Base;

/**
 * 嗨爆小片上传接口
 */
class Upload extends Base
{

    public function set_new()
    {
        $category = trim($this->request->post('category'));
        $title = $this->request->post('title');
        $cover = $this->request->post('cover');
        $url = $this->request->post('url');
        $duration = $this->request->post('duration');

        switch ($category) {
            case '美女': $category_id = 22; break;
            case '搞笑': $category_id = 23; break;
            case '正能量': $category_id = 24; break;
            case '美食': $category_id = 27; break;
            case '体育': $category_id = 28; break;
            case '生活': $category_id = 29; break;
            case '科技': $category_id = 30; break;
        }

        $keyword = substr($url, -16, -5);

        $new = new HaibaoVideo();
        $new->category_id = $category_id;
        $new->title = $title;
        $new->cover = $cover;
        $new->type = 'tx';
        $new->keyword = $keyword;
        $new->duration = $duration;
        $new->play_num = mt_rand(16,153)/10;
        $res = $new->save();
        return json($res);
    }

}
